package manage.util;

import manage.model.Pay;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.*;
import java.net.URL;
import java.util.Properties;

public class PayUtil {
    public static int readProperty2() {
        Properties properties = new Properties();
        int a = 0;
        try {
            properties = PropertiesLoaderUtils.loadAllProperties("pay.properties");
            a = Integer.parseInt(properties.getProperty("A"));
            a+= Integer.parseInt(properties.getProperty("B"));
            a+= Integer.parseInt(properties.getProperty("C"));
            a+= Integer.parseInt(properties.getProperty("D"));
            a+= Integer.parseInt(properties.getProperty("E"));
            a+= Integer.parseInt(properties.getProperty("F"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return a;
    }
    public static FSIAOHF getFSIAOHF(){
        FSIAOHF fsiaohf = new FSIAOHF();
        Properties properties = new Properties();
        int a = 0;
        try {
            File file=new File(PayUtil.class.getClassLoader().getResource("").getPath(),"pay.properties");
            InputStream in = new BufferedInputStream (new FileInputStream(file));
            properties.load(in);
            fsiaohf.setA(properties.getProperty("A"));
            fsiaohf.setB(properties.getProperty("B"));
            fsiaohf.setC(properties.getProperty("C"));
            fsiaohf.setD(properties.getProperty("D"));
            fsiaohf.setE(properties.getProperty("E"));
            fsiaohf.setF(properties.getProperty("F"));

        } catch (IOException e) {
            e.printStackTrace();
        }
        return fsiaohf;
    }

    public static FSIAOHF setFSIAOHF(FSIAOHF fsiaohf){
        Properties properties = new Properties();
        int a = 0;
        try {
            File file=new File(PayUtil.class.getClassLoader().getResource("").getPath(),"pay.properties");
            InputStream in = new BufferedInputStream (new FileInputStream(file));
            properties.load(in);
            System.out.println(properties.getProperty("A"));
            properties.setProperty("A",fsiaohf.getA());
            properties.setProperty("B",fsiaohf.getB());
            properties.setProperty("C",fsiaohf.getC());
            properties.setProperty("D",fsiaohf.getD());
            properties.setProperty("E",fsiaohf.getE());
            properties.setProperty("F",fsiaohf.getF());
            System.out.println(properties.getProperty("A"));
            System.out.println(file.getPath());
            FileOutputStream outputFile = new FileOutputStream(file);
            properties.store(outputFile,"");
            outputFile.flush();
            outputFile.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
        return fsiaohf;
    }
}
